package com.payment.ktb.adapter;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.payment.ktb.Interface.AlertInterface;
import com.payment.ktb.R;
import com.payment.ktb.constants.ConstantsCustomer;
import com.payment.ktb.constants.ConstantsOrderManage;
import com.payment.ktb.constants.ConstantsPayType;
import com.payment.ktb.model.CustomerManageEntity;
import com.payment.ktb.model.OrderManageEntity;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.StringUtils;

import java.util.List;

/**
 * Created by admin on 2017/9/22.
 */

public class OrderManageAdapter extends BaseAdapter {

    private Context mContext;
    private List<OrderManageEntity> listdatas;

    public OrderManageAdapter(Context mContext, List<OrderManageEntity> listdatas) {
        this.mContext = mContext;
        this.listdatas = listdatas;
    }

    public OrderManageAdapter() {
    }

    @Override
    public int getCount() {
        return listdatas.size();
    }

    @Override
    public Object getItem(int i) {
        return listdatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(mContext, R.layout.adapter_ordermanage_item,null);
            viewHolder.tv_ordermanage_orderPrice = (TextView) view.findViewById(R.id.tv_ordermanage_orderPrice);
            viewHolder.tv_ordermanage_userName = (TextView) view.findViewById(R.id.tv_ordermanage_userName);
            viewHolder.tv_ordermanage_orderNo = (TextView) view.findViewById(R.id.tv_ordermanage_orderNo);
            viewHolder.tv_ordermanage_orderStatus = (TextView) view.findViewById(R.id.tv_ordermanage_orderStatus);
            viewHolder.tv_ordermanage_orderReqTime = (TextView) view.findViewById(R.id.tv_ordermanage_orderReqTime);
            viewHolder.tv_ordermanage_payType = (TextView) view.findViewById(R.id.tv_ordermanage_payType);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }


        viewHolder.tv_ordermanage_orderPrice.setText("¥" + StringUtils.handleFen2Yuan(listdatas.get(i).getOrderPrice() + ""));

        viewHolder.tv_ordermanage_userName.setText(listdatas.get(i).getUserName());

        viewHolder.tv_ordermanage_orderNo.setText(listdatas.get(i).getOrderNo());

        viewHolder.tv_ordermanage_orderStatus.setText(ConstantsOrderManage.getStatus((listdatas.get(i).getOrderStatus())));
        if (listdatas.get(i).getOrderStatus() == ConstantsOrderManage.INIT.getCode()) {
            viewHolder.tv_ordermanage_orderStatus.setTextColor(mContext.getResources().getColor(R.color.orange));
        }else if (listdatas.get(i).getOrderStatus() == ConstantsOrderManage.SUCC.getCode()) {
            viewHolder.tv_ordermanage_orderStatus.setTextColor(mContext.getResources().getColor(R.color.green));
        }else if (listdatas.get(i).getOrderStatus() == ConstantsOrderManage.FAIL.getCode()) {
            viewHolder.tv_ordermanage_orderStatus.setTextColor(mContext.getResources().getColor(R.color.red));
        }




        viewHolder.tv_ordermanage_orderReqTime.setText(listdatas.get(i).getOrderReqTime());

        viewHolder.tv_ordermanage_payType.setText(ConstantsPayType.getStatus(listdatas.get(i).getPayType()));



        return view;
    }


    class ViewHolder {

        TextView tv_ordermanage_orderPrice;
        TextView tv_ordermanage_userName;
        TextView tv_ordermanage_orderNo;
        TextView tv_ordermanage_orderStatus;
        TextView tv_ordermanage_orderReqTime;
        TextView tv_ordermanage_payType;

    }

}
